package com.ruoyi.project.gxgw_modules.goods.service;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.gxgw_modules.goods.mapper.GoodsMapper;
import com.ruoyi.project.gxgw_modules.goods.domain.Goods;
import com.ruoyi.project.gxgw_modules.goods.service.IGoodsService;
import com.ruoyi.common.support.Convert;
import com.ruoyi.common.utils.StringUtils;

/**
 * 商品 服务层实现
 * 
 * @author ruoyi
 * @date 2019-01-20
 */
@Service
public class GoodsServiceImpl implements IGoodsService 
{
	@Autowired
	private GoodsMapper goodsMapper;

	/**
     * 查询商品信息
     * 
     * @param goodsId 商品ID
     * @return 商品信息
     */
    @Override
	public Goods selectGoodsById(Integer goodsId)
	{
	    return goodsMapper.selectGoodsById(goodsId);
	}
	
	/**
     * 查询商品列表
     * 
     * @param goods 商品信息
     * @return 商品集合
     */
	@Override
	public List<Goods> selectGoodsList(Goods goods)
	{
	    return goodsMapper.selectGoodsList(goods);
	}
	
    /**
     * 新增商品
     * 
     * @param goods 商品信息
     * @return 结果
     */
	@Override
	public int insertGoods(Goods goods)
	{
	    return goodsMapper.insertGoods(goods);
	}
	
	/**
     * 修改商品
     * 
     * @param goods 商品信息
     * @return 结果
     */
	@Override
	public int updateGoods(Goods goods)
	{
	    return goodsMapper.updateGoods(goods);
	}

	/**
     * 删除商品对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteGoodsByIds(String ids)
	{
		return goodsMapper.deleteGoodsByIds(Convert.toStrArray(ids));
	}
//下面是唯一性检验，0代表唯一即可以进行增加或修改，1代表不唯一
	@Override
	public String checkGoodsNameUnique(Goods goods) {
		// TODO Auto-generated method stub
		Long goodsId = StringUtils.isNull(goods.getGoodsId()) ? -1L : goods.getGoodsId();
	       Goods info = goodsMapper.checkGoodsNameUnique(goods.getGoodsName());
	       if (StringUtils.isNotNull(info) && info.getGoodsId().longValue() != goodsId.longValue())
	        {
	            return "1";
	        }
	        return "0";
	}

	@Override
	public String checkGoodsBarUnique(Goods goods) {
		// TODO Auto-generated method stub
		 Long goodsId = StringUtils.isNull(goods.getGoodsId()) ? -1L : goods.getGoodsId();
	       Goods info = goodsMapper.checkGoodsBarUnique(goods.getGoodsBar());
	       if (StringUtils.isNotNull(info) && info.getGoodsId().longValue() != goodsId.longValue())
	        {
	            return "1";
	        }
	        return "0";
	}

	@Override
	public int addNum(Integer goodsId,Integer inputNum) {
		// TODO Auto-generated method stub
		return goodsMapper.addNum(goodsId,inputNum);
	}

	@Override
	public int reduceNum(Integer goodsId,Integer inputNum) {
		// TODO Auto-generated method stub
		return goodsMapper.reduceNum(goodsId,inputNum);
	}

	@Override
	public int selectNum(Integer goodsId) {
		// TODO Auto-generated method stub
		return goodsMapper.selectNum(goodsId);
	}

	@Override
	public int checkInputRecord(Integer goodsId) {
		// TODO Auto-generated method stub
		return goodsMapper.checkInputRecord(goodsId);
	}

	@Override
	public int checkOutputRecord(Integer goodsId) {
		// TODO Auto-generated method stub
		return goodsMapper.checkOutputRecord(goodsId);
	}
	
}
